<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"
      >
    <f:metadata>
        <f:viewParam name="userid" value="#{frontController.userID}" valueChangeListener="#{frontController.logIn}"/>

    </f:metadata>
    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            #{bundle.NewAdv}
        </ui:define>
        <ui:define name="menuitem">addAdv.xhtml</ui:define>
        <ui:define name="body">
        </ui:define>
        <ui:define name="user">
            <ui:include src="/sections/fileUploadDialog.xhtml" />
            <table>
                <tr><td>
                        <ui:include src="/sections/map.xhtml" />
                    </td><td class="mapright">
                        <h:outputScript name="advs.js"/>   
                        <script>
                            initArray.push(prepare_newadvert_form);  
                            show_add_marker=true;
                        </script>    
                        <h:form id="newadvert" prependId="false">
                            <p:panel>
                                <h:inputHidden id="lat" value="#{advertController.newAdvert.lat}"/>
                                <h:inputHidden id="lng" value="#{advertController.newAdvert.lng}"/>
                                <h:outputLabel value="#{advertController.newAdvert.user.displayname}"/>
                                <table width="100%">
                                    <tr>
                                        <td><h:outputLabel value="#{bundle.Address}"/></td>
                                        <td><h:inputHidden id="address_input" value="#{advertController.newAdvert.address}"/>
                                            <p:inputText id="address" value="#{advertController.newAdvert.address}" onchange="changedEdit()"/><p:button id="editadr" value="#{bundle.Edit}" onclick="pressEdit();return false" />
                                        </td>
                                    </tr>

                                    <tr id="rooms">
                                        <td width="20%">
                                            <h:outputLabel value="#{bundle.RoomsCount}" />
                                        </td>
                                        <td >
                                            <p:selectOneMenu id="RoomsSelector" value="#{advertController.newAdvert.room_count}" styleClass="label_width" >  
                                                <f:selectItem itemLabel="#{bundle.Rooms1}" itemValue="1" />  
                                                <f:selectItem itemLabel="#{bundle.Rooms2}" itemValue="2" />  
                                                <f:selectItem itemLabel="#{bundle.Rooms3}" itemValue="3" /> 
                                                <f:selectItem itemLabel="#{bundle.Rooms4plus}" itemValue="4" /> 
                                                <f:selectItem itemLabel="#{bundle.Rooms0}" itemValue="-1" />  
                                            </p:selectOneMenu>
                                        </td>
                                    </tr>
                                    <tr id="price">
                                        <td width="20%">
                                            <h:outputLabel value="#{bundle.Price}" />
                                        </td>
                                        <td >
                                            <h:outputLabel value="" />                                        
                                            <p:inputText id="Price" value="#{advertController.newAdvert.price}"  size="2"/>  
                                            <h:outputLabel value="'000$"/>
                                        </td>
                                    </tr>
                                    <tr id="totalarea">
                                        <td width="20%">
                                            <h:outputLabel value="#{bundle.TotalSqure}" />
                                        </td>
                                        <td >
                                            <h:outputLabel value="" />                                        
                                            <p:inputText id="TotalArea" value="#{advertController.newAdvert.total_sqr}"  size="3"/>m<sup>2</sup>  
                                        </td>
                                    </tr>
                                    <tr id="livingarea">
                                        <td width="20%">
                                            <h:outputLabel value="#{bundle.LivingSqure}" />
                                        </td>
                                        <td >
                                            <h:outputLabel value="" />                                        
                                            <p:inputText id="LivingArea" value="#{advertController.newAdvert.living_sqr}"  size="3"/>m<sup>2</sup>  
                                        </td>
                                    </tr>
                                    <tr id="kitchenarea">
                                        <td width="20%">
                                            <h:outputLabel value="#{bundle.KitchenSqure}" />
                                        </td>
                                        <td >
                                            <h:outputLabel value="" />                                        
                                            <p:inputText id="KitchenArea" value="#{advertController.newAdvert.kitchen_sqr}"  size="3"/>m<sup>2</sup>  
                                        </td>
                                    </tr>
                                    <tr id="balconarea">
                                        <td width="20%">
                                            <h:outputLabel value="#{bundle.BalkonySqure}" />
                                        </td>
                                        <td >
                                            <h:outputLabel value="" />                                        
                                            <p:inputText id="BalconArea" value="#{advertController.newAdvert.balkony_sqr}"  size="3"/>m<sup>2</sup>  
                                        </td>
                                    </tr>

                                    <tr id="flors">
                                        <td width="20%">
                                            <h:outputLabel value="#{bundle.Floor}" />
                                        </td>
                                        <td >
                                            <h:outputLabel value="" />
                                            <p:inputText id="Flor" value="#{advertController.newAdvert.floor}"  size="2"/>  

                                            <h:outputLabel value=" #{bundle.of} " />
                                            <p:inputText id="Flors" value="#{advertController.newAdvert.floors}" size="2"/>  
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="20%">
                                            <h:outputLabel value="#{bundle.Note}" />
                                        </td>
                                        <td >
                                            <p:inputTextarea id="notes" value="#{advertController.newAdvert.notes}" />
                                        </td>
                                    </tr>
                                </table>
                                <div class="hide">
                                    <h:inputText id="lats" value="#{addressLookup.bounds.slat}"/>
                                    <h:inputText id="latn" value="#{addressLookup.bounds.nlat}"/>
                                    <h:inputText id="lngw" value="#{addressLookup.bounds.wlng}"/>
                                    <h:inputText id="lnge" value="#{addressLookup.bounds.elng}"/>
                                </div>
                                <p:commandButton id="add" value="#{bundle.Save}"  action="#{advertController.advertSave()}" onclick="prepareEdit()" update=":newadvert :advs" oncomplete="prepare_newadvert_form()"/>
                                <p:commandButton id="clear" value="#{bundle.New}"  action="#{advertController.advertClear()}" onclick="prepareEdit()" update=":newadvert :filesform" oncomplete="prepare_newadvert_form()"/>
                                <p:commandButton id="images" value="#{bundle.Images}" action="#{fileUploadController.showDialog()}" update=":filesform :newadvert" onclick="fsd.show()"/>
                            </p:panel>
                            <p:galleria id="gal" value="#{advertController.newAdvert.files}" var="image"
                                        transitionInterval="0"
                                        frameHeight="50"
                                        frameWidth="50"
                                        panelHeight="0"
                                        panelWidth="300"
                                        >
                                <p:graphicImage value="/upload/#{image.userName.name}/#{image.name}" width="50" height="50"  /> 
                                <p:galleriaContent>
                                    <p:graphicImage value="/upload/#{image.userName.name}/#{image.name}" width="50" height="50"  /> 
                                </p:galleriaContent> 
                                
                            </p:galleria>                            
                        </h:form>
                    </td></tr>
            </table>
            <h:form id="advs">
                <div class="advs_scroll" >
                    <p:ajaxStatus oncomplete="parseTable()" />
                    <p:dataTable id="advslist" value="#{advertController.useradverts}" var="adv" 
                                 paginator="true" rows="20"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="10,20,50, 100"> 
                        <f:facet name="header">  
                            #{bundle.ListAdvTable}
                        </f:facet> 
                        <p:column><f:facet name="header">#</f:facet> 
                            <p:commandLink update=":newadvert :filesform" oncomplete="setMapCenter(#{adv.lat},#{adv.lng});setMarkerPosition(#{adv.lat},#{adv.lng})">
                                <f:setPropertyActionListener value="#{adv}" target="#{advertController.newAdvert}"/>
                            <h:graphicImage url="/resources/images/markers/#{adv.printIconName(adv)}" />
                            <h:inputHidden id="lat#{adv.number}" value="#{adv.lat}" />
                            <h:inputHidden id="lng#{adv.number}" value="#{adv.lng}" />
                            </p:commandLink>

                        </p:column>
                        <p:column>
                            <f:facet name="header">#{bundle.Address}</f:facet> 
                            <ez:advertView item="#{adv}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header">#{bundle.Note}</f:facet> 
                             <p:panel style="width:300px">
                                <h:outputText value="#{adv.notes}" />
                            </p:panel>
                        </p:column>
                        <p:column>
                            <p:commandButton icon="ui-icon-cancel" action="#{advertController.advertRemove(adv)}" update=":newadvert :advs" />
                        </p:column>
                    </p:dataTable>
                </div>

            </h:form>   

        </ui:define>
        <ui:define name="guest">
            #{bundle.RegisterFirst}
        </ui:define>

    </ui:composition>
</html>
